#include<bits/stdc++.h>
using namespace std;
typedef vector<int> ve;  

void slove()
{
	int m, n, a, b, d;
	cin >> m >> n >> a >> b >> d;
	map<int, int> row;
	map<int, int> col;
	for (int i = 0; i < d; i++)
	{
		int x1, x2; int y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if (x1 == x2)//列不同
			col[min(y1, y2)]++;
		else //行不同
			row[min(x1, x2)]++;
	}
	//将所有的键值对拷贝过来
	vector<pair<int,int>> sort_row(row.begin(),row.end());  
	vector<pair<int, int>>sort_col(col.begin(), col.end()); 
	sort(sort_row.begin(), sort_row.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
		return a.second > b.second;  
		});
	sort(sort_col.begin(), sort_col.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
		return a.second > b.second;  
		});
	auto it = sort_row.begin();
	{
		cout << (it++)->first << " ";
	}
	cout << endl;
	auto it_ = sort_col.begin();
	for (int i = 0; i < b; i++)
	{
		cout << (it_++)->first << " ";
	}
	cout << endl;
}

int main()
{
	slove();
	return 0;
}
